<template>
  <div class="home">
    <pre>result:{{ result }}</pre>
    <input type="text" v-model="user.username" />
    <input type="text" v-model="user.password" />
    <input
      type="button"
      value="发送简单得异步请求-get"
      @click="sendRequest()"
    />
    <input
      type="button"
      value="发送简单得异步请求-post"
      @click="sendRequest2()"
    />
  </div>
</template>

<script>
import request from "../util/request";
export default {
  name: "HomeView",
  data() {
    return {
      user: {
        username: "",
        password: "",
      },
      result: {},
    };
  },
  methods: {
    async sendRequest() {
      try {
        let { data } = await request({
          url: "/query",
          method: "get",
          params: this.user,
        });
        this.result = data;
      } catch (error) {
        alert("请求失败");
      }
    },
    async sendRequest2() {
      try {
        let { data } = await request({
          url: "/body",
          method: "post",
          params: this.user,
        });
        this.result = data;
      } catch (error) {
        alert("请求失败");
      }
    },
  },
};
</script>
